layui.use(['form', 'layer', 'jquery'], function () {

    $ = layui.jquery;
    let form = layui.form,
        layer = layui.layer;

    //监听提交
    form.on('submit(add)',
        function (data) {
            data = data.field;
            //console.log(data);
            //发异步，把数据提交给java
            $.ajax({
                url: '/back/product/type/add',
                data: data,
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.count === 1) {
                        layer.alert("增加成功", {
                                icon: 6
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();

                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    } else if (res.msg ==='error') {
                        layer.alert("类型已存在");
                    }
                    else {
                        layer.alert("增加失败");
                    }

                }
            })
            return false;
        });
});